package resource.pojo;

import java.io.Serializable;
import java.sql.ResultSet;
import java.util.Date;

import model.pojo.Employee;
import models.util.MySqlDataAccessHelper;

public class Approvedoc implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String iDApproveDoc;
	private String title;
	private String content;
	private String content2;
	private boolean tripDateFlag=true;
	

	public boolean isTripDateFlag() {
		return tripDateFlag;
	}

	public void setTripDateFlag(boolean tripDateFlag) {
		this.tripDateFlag = tripDateFlag;
	}

	public String getContent2() {
		return content2;
	}

	public void setContent2(String content2) {
		this.content2 = content2;
	}

	private String iDEmployee;
	private String iDGroupApprove;
	private Date timecreate;
	private Integer iDStatus;
	private Integer iDTypeDoc;
	private Date timeApprove;
	private String comment;
	private String description;
	private String purpose;
	private String employeePerforment;
	private Date tripDate;
	private String totalTime;
	private String location;
	private Typedoc typeDoc;
	private String typeName;
	private GroupApprove groupApprove;
	private Employee employee;
	private Status status;
	private boolean checkAddReceiver = false;
	MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();

	public MySqlDataAccessHelper getMysqlHelper() {
		return mysqlHelper;
	}

	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
		this.mysqlHelper = mysqlHelper;
	}

	public Approvedoc() {
	}

	public Approvedoc(String iDApproveDoc, String title,Integer iDTypeDoc, Date timecreate, Date timeApprove){
		this.iDApproveDoc=iDApproveDoc;
		this.title=title;
		this.iDTypeDoc=iDTypeDoc;
		this.timecreate=timeApprove;
		this.timeApprove=timeApprove;
	}
	
	public Approvedoc(String iDApproveDoc, String title, String content,
			String iDEmployee, String iDGroupApprove, Date timecreate,
			Integer iDStatus, Integer iDTypeDoc, Date timeApprove,
			String comment, String description) {
		super();
		this.iDApproveDoc = iDApproveDoc;
		this.title = title;
		this.content = content;
		this.iDEmployee = iDEmployee;
		this.iDGroupApprove = iDGroupApprove;
		this.timecreate = timecreate;
		this.iDStatus = iDStatus;
		this.iDTypeDoc = iDTypeDoc;
		this.timeApprove = timeApprove;
		this.comment = comment;
		this.description = description;
		
	}
	
	public Approvedoc(String iDApproveDoc, String title, String content,
			String iDEmployee, String iDGroupApprove, Date timecreate,
			Integer iDStatus, Integer iDTypeDoc, Date timeApprove,
			String comment,String description,String purpose, String employeePerforment, Date tripDate, String totalTime, String location) {
		super();
		this.iDApproveDoc = iDApproveDoc;
		this.title = title;
		this.content = content;
		this.iDEmployee = iDEmployee;
		this.iDGroupApprove = iDGroupApprove;
		this.timecreate = timecreate;
		this.iDStatus = iDStatus;
		this.iDTypeDoc = iDTypeDoc;
		this.timeApprove = timeApprove;
		this.comment=comment;
		this.description = description;
		this.purpose = purpose;
		this.employeePerforment = employeePerforment;
		this.tripDate = tripDate ;
		this.totalTime = totalTime;
		this.location = location;
	}

	public String getiDApproveDoc() {
		return iDApproveDoc;
	}

	public void setiDApproveDoc(String iDApproveDoc) {
		this.iDApproveDoc = iDApproveDoc;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getiDEmployee() {
		return iDEmployee;
	}

	public void setiDEmployee(String iDEmployee) {
		this.iDEmployee = iDEmployee;
	}

	public Date getTimecreate() {
		return timecreate;
	}

	public void setTimecreate(Date timecreate) {
		this.timecreate = timecreate;
	}

	public Integer getiDStatus() {
		return iDStatus;
	}

	public void setiDStatus(Integer iDStatus) {
		this.iDStatus = iDStatus;
	}

	public String getiDGroupApprove() {
		return iDGroupApprove;
	}

	public void setiDGroupApprove(String iDGroupApprove) {
		this.iDGroupApprove = iDGroupApprove;
	}

	public Integer getiDTypeDoc() {
		return iDTypeDoc;
	}

	public void setiDTypeDoc(Integer iDTypeDoc) {
		this.iDTypeDoc = iDTypeDoc;
	}

	public Date getTimeApprove() {
		return timeApprove;
	}

	public void setTimeApprove(Date timeApprove) {
		this.timeApprove = timeApprove;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Typedoc getTypeDoc() {
		mysqlHelper.open();
		try {
			String sql = "select * from typedoc where IDTypeDoc="
					+ this.getiDTypeDoc();
			ResultSet rs = mysqlHelper.executeQuery(sql);
			if (rs.next()) {
				typeDoc = new Typedoc(rs.getInt("IDConfigStaticLang"));
				ConfigStaticLang configStaticLang = typeDoc
						.getConfigStaticLang();
				if (configStaticLang != null) {
					typeDoc.setiDTypeDoc(rs.getInt("IDTypeDoc"));
					typeDoc.setTypeName(configStaticLang.getNameByLang("EN"));
					typeDoc.setiDContentDoc(rs.getInt("IDContentDoc"));
					typeDoc.setiDTemplate(rs.getInt("IDTemplate"));
					typeDoc.setDescription(rs.getString("Description"));
				} else {
					typeDoc.setiDTypeDoc(rs.getInt("IDTypeDoc"));
					typeDoc.setTypeName(rs.getString("TypeName"));
					typeDoc.setiDContentDoc(rs.getInt("IDContentDoc"));
					typeDoc.setiDTemplate(rs.getInt("IDTemplate"));
					typeDoc.setDescription(rs.getString("Description"));
				}
			}
		} catch (Exception e) {
		}
		return typeDoc;
	}

	public void setTypeDoc(Typedoc typeDoc) {
		this.typeDoc = typeDoc;
	}

	public GroupApprove getGroupApprove() {
		mysqlHelper.open();
		try {
			String sql = "select * from groupapprove where IDGroupApprove='"
					+ this.getiDGroupApprove() + "'";
			ResultSet rs = mysqlHelper.executeQuery(sql);
			if (rs.next()) {
				groupApprove = new GroupApprove(rs.getString("IDGroupApprove"),
						rs.getBoolean("StatusUse"), rs.getString("GroupName"),
						rs.getString("Description"));
			}
			System.out.println("Group ");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysqlHelper.close();
		}
		return groupApprove;
	}

	public void setGroupApprove(GroupApprove groupApprove) {
		this.groupApprove = groupApprove;
	}

	public Employee getEmployee() {
		mysqlHelper.open();
		try {
			String sql = "select * from employee where IDEmployee='"
					+ this.iDEmployee + "'";
			ResultSet rs = mysqlHelper.executeQuery(sql);
			while (rs.next()) {
				employee = new Employee(rs.getString("IDEmployee"),
						rs.getString("UserName"), rs.getString("Password"),
						rs.getString("FullName"), rs.getString("Phone"),
						rs.getDate("Birthday"), rs.getString("Address"),
						rs.getString("Email"), rs.getString("Sex"),
						rs.getString("Position"), rs.getString("IDManager"),
						rs.getInt("IDDepartment"), rs.getInt("IDRole"),
						rs.getString("Description"));
			}
		} catch (Exception e) {

		} finally {
			mysqlHelper.close();
		}
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Status getStatus() {
		mysqlHelper.open();
		try {
			String sql = "select * from status where IDStatus="
					+ this.getiDStatus();
			ResultSet rs = mysqlHelper.executeQuery(sql);
			if (rs.next()) {

				status = new Status(rs.getInt("IDConfigStaticLang"));
				ConfigStaticLang configStaticLang = status
						.getConfigStaticLang();
				if (configStaticLang != null) {
					status.setiDStatus(rs.getInt("IDStatus"));
					status.setStatusName(configStaticLang.getNameByLang("EN"));
					status.setDescription(rs.getString("Description"));
				} else {
					status.setiDStatus(rs.getInt("IDStatus"));
					status.setStatusName(rs.getString("StatusName"));
					status.setDescription(rs.getString("Description"));
				}
			}
		} catch (Exception e) {
		} finally {
			mysqlHelper.close();
		}

		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((iDApproveDoc == null) ? 0 : iDApproveDoc.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Approvedoc other = (Approvedoc) obj;
		if (iDApproveDoc == null) {
			if (other.iDApproveDoc != null)
				return false;
		} else if (!iDApproveDoc.equals(other.iDApproveDoc))
			return false;
		return true;
	}

	@Override
	public String toString(){
		return title;
	}

	public boolean isCheckAddReceiver() {
		return checkAddReceiver;
	}

	public void setCheckAddReceiver(boolean checkAddReceiver) {
		this.checkAddReceiver = checkAddReceiver;
	}
	
	public String getPurpose() {
		return purpose;
	}

	public void setPurpose(String purpose) {
		this.purpose = purpose;
	}
	
	public String getEmployeePerforment() {
		return employeePerforment;
	}

	public void setEmployeePerforment(String employeePerforment) {
		this.employeePerforment = employeePerforment;
	}

	public Date getTripDate() {
		return tripDate;
	}

	public void setTripDate(Date tripDate) {
		this.tripDate = tripDate;
	}

	public String getTotalTime() {
		return totalTime;
	}

	public void setTotalTime(String totalTime) {
		this.totalTime = totalTime;
	}
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
	public String toString1(){
		return title;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

}
